package com.cyx;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author 陈裕星
 * @version 1.0
 */
public class 最长回文子串之中心扩散法 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] chars = str.toCharArray();
        int max = 0;//记录最长子串长度
        int currMax = 0;
        int start = 0;//记录最长子串的起始坐标
        for (int i = 0; i < chars.length; i++) {
            currMax = Math.max(getPalindromeLength(chars,i,i),getPalindromeLength(chars,i , i+1));
            if(currMax > max){
                max = currMax;
                start = i - (currMax + 1) / 2 + 1;
            }
        }
        //输出最长子串
        System.out.println(max);
        System.out.println(str.substring(start,start+max));
    }
    //找出最长子串
    static int getPalindromeLength(char[] chars,int l,int r){
        int len = 0;
        while(l >= 0 && r < chars.length && chars[l] == chars[r]){
            len = r - l + 1;//记录长度
            l--;
            r++;
        }
        return len;
    }
}

